<?php
defined('IN_TS') or die('Access Denied.');

//头文件包含
include_once 'public/php/defines.php';
include_once 'app/geoweibo/api/def.php';
include_once 'app/geoweibo/api/api_do.php';

switch($ts){
    //读取
    case "search":
    {
        $arr = search($new["geoweibo"]);
        break;
    }
    
	//评论
	case "comment":
	{
		//用户是否登录
		$userid = aac('user')->isLogin();
	
		$geoweibo_id	= intval($_POST['geoweibo_id']);
		$content		= tsClean($_POST['content']);
		
		if($TS_USER['user']['isadmin']==0){
			//过滤内容开始
			aac('system')->antiWord($content);
			//过滤内容结束
		}
		
		$commentid = $new['geoweibo']->create(TABLE_GEOWEIBO_COMMENT,array(
			COL_GEOWEIBO_ID	=> $geoweibo_id,
			COL_USER_ID		=> $userid,
			COL_COMMENT		=> $content,
			COL_ADDTIME		=> date('Y-m-d H:i:s'),
		));
		
		//计算评论总数
		$commentNum = $new['geoweibo']->findCount(TABLE_GEOWEIBO_COMMENT,array(
			COL_GEOWEIBO_ID => $geoweibo_id,
		));

		$new['geoweibo']->update(TABLE_GEOWEIBO, array(
			COL_GEOWEIBO_ID => $geoweibo_id,
		),array(
			COL_COUNT_COMMENT => $commentNum,
		));

		header("Location: ".tsUrl('geoweibo','index'));
		
		$arr = array(
            FLAG_RET => NO_ERR
        );
		
		break;
	}
	
	//搜索评论
	case "comment_search":
	{
		$geoweibo_id = intval($_POST['geoweibo_id']);
		$arr = comment_search($new["geoweibo"], $geoweibo_id);
		break;
	}
	
    default:
    {
        $arr = array(
            FLAG_RET => ERROR,
            FLAG_ERR_CODE => ERR_VAL
        );
        break;
    }
}

/*返回结果*/
echo json_encode($arr);

?>